//
//  YDUserExperienceViewController.m
//  IngCard
//
//  Created by kf on 2017/8/31.
//  Copyright © 2017年 IngDan. All rights reserved.
//

#import "YDUserExperienceEditViewController.h"

@interface YDUserExperienceEditViewController ()
@property(nonatomic, strong) UITextField *titleTextField;
@property(nonatomic, strong) UITextField *companyTextField;
@property(nonatomic, strong) UITextField *locationTextField;
@property(nonatomic, strong) UITextField *startTextField;
@property(nonatomic, strong) UITextField *endTextField;
@property(nonatomic, strong) UITextField *contentTextField;
@end

@implementation YDUserExperienceEditViewController

- (void) viewDidLoad
{
    [super viewDidLoad];
    
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithTitle:@"确定"
                                                                  style:UIBarButtonItemStyleDone
                                                                 target:self
                                                                 action:@selector(rightBarItemClick:)];
    rightItem.tintColor = UIColorMake(60, 44, 44);
    
    
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithTitle:@"取消"
                                                                 style:UIBarButtonItemStyleDone
                                                                target:self
                                                                action:@selector(rightBarItemClick:)];
    leftItem.tintColor = UIColorMake(60, 44, 44);
    self.navigationItem.rightBarButtonItem = rightItem;
    self.navigationItem.leftBarButtonItem = leftItem;
}

- (void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [THEME renderStatusBarStyle:YDStatusBarStyle_Dark];
    [THEME renderNavigationBar:self style:YDNavigationStyle_Gray];
    
    self.titleTextField.placeholder =  (self.model > 0) ?@"职位":@"学校";
    self.companyTextField.placeholder = (self.model > 0) ?@"公司":@"学位";
    self.locationTextField.placeholder = (self.model > 0) ?@"地点":@"专业";
    self.startTextField.placeholder = (self.model > 0) ?@"入职时间":@"入学时间";
    self.endTextField.placeholder = (self.model > 0) ?@"离职时间":@"毕业时间";
    self.contentTextField.placeholder = (self.model > 0) ?@"工作内容":@"获得奖励";
}

- (void) viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear: animated];
    [THEME renderStatusBarStyle:YDStatusBarStyle_Light];
}

-(void) initSubviews
{
    [super  initSubviews];
    self.title = (self.model > 0) ? @"修改工作经历" : @"修改教育经历";
    
    [self.view addSubview:self.titleTextField];
    [self.titleTextField makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(33);
        make.right.equalTo(-42);
        make.bottom.equalTo(self.view.mas_top).offset(132);
    }];
    
    [self.view addSubview:self.companyTextField];
    [self.companyTextField makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleTextField);
        make.right.equalTo(self.titleTextField);
        make.bottom.equalTo(self.titleTextField).offset(83);
    }];
    
    [self.view addSubview:self.locationTextField];
    [self.locationTextField makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleTextField);
        make.right.equalTo(self.titleTextField);
        make.bottom.equalTo(self.companyTextField).offset(83);
    }];
    
    
    [self.view addSubview:self.startTextField];
    [self.startTextField makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleTextField);
        make.width.equalTo(120);
        make.bottom.equalTo(self.locationTextField).offset(83);
    }];
    
    
    [self.view addSubview:self.endTextField];
    [self.endTextField makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(-42);
        make.width.equalTo(120);
        make.bottom.equalTo(self.locationTextField).offset(83);
    }];
    
    [self.view addSubview:self.contentTextField];
    [self.contentTextField makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleTextField);
        make.right.equalTo(self.titleTextField);
        make.bottom.equalTo(self.startTextField).offset(83);
    }];
}


#pragma mark - Private
- (void)rightBarItemClick:(UIBarButtonItem *)item
{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - lazy loading
-(UITextField *) titleTextField
{
    if(!_titleTextField)
    {
        _titleTextField = [[UITextField alloc]init];
        _titleTextField.keyboardType = UIKeyboardTypeDefault;
        _titleTextField.placeholder = @"职位";
        
        [_titleTextField setStyle:^(UIView *target) {
            UITEXTFIELDSTYLE;
            temp.font = UILightFontMake(20);
            temp.textColor = UIColorMake(87, 83, 83);
            temp.textAlignment = NSTextAlignmentLeft;
        }];
        
        UIView *line= [UIView new];
        line.backgroundColor = UIColorMake(200, 199, 204);
        [_titleTextField addSubview:line];
        [line makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(0);
            make.width.equalTo(_titleTextField);
            make.top.equalTo(_titleTextField.mas_bottom).offset(1);
            make.height.equalTo(1);
        }];
    }
    return _titleTextField;
}



-(UITextField *) companyTextField
{
    if(!_companyTextField)
    {
        _companyTextField = [[UITextField alloc]init];
        _companyTextField.keyboardType = UIKeyboardTypeDefault;
        _companyTextField.placeholder = @"公司";
        
        [_companyTextField setStyle:^(UIView *target) {
            UITEXTFIELDSTYLE;
            temp.font = UILightFontMake(20);
            temp.textColor = UIColorMake(87, 83, 83);
            temp.textAlignment = NSTextAlignmentLeft;
        }];
        
        UIView *line= [UIView new];
        line.backgroundColor = UIColorMake(200, 199, 204);
        [_companyTextField addSubview:line];
        [line makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(0);
            make.width.equalTo(_companyTextField);
            make.top.equalTo(_companyTextField.mas_bottom).offset(1);
            make.height.equalTo(1);
        }];
    }
    return _companyTextField;
}


-(UITextField *) locationTextField
{
    if(!_locationTextField)
    {
        _locationTextField = [[UITextField alloc]init];
        _locationTextField.keyboardType = UIKeyboardTypeDefault;
        _locationTextField.placeholder = @"办公地点";
        
        [_locationTextField setStyle:^(UIView *target) {
            UITEXTFIELDSTYLE;
            temp.font = UILightFontMake(20);
            temp.textColor = UIColorMake(87, 83, 83);
            temp.textAlignment = NSTextAlignmentLeft;
        }];
        
        UIView *line= [UIView new];
        line.backgroundColor = UIColorMake(200, 199, 204);
        [_locationTextField addSubview:line];
        [line makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(0);
            make.width.equalTo(_locationTextField);
            make.top.equalTo(_locationTextField.mas_bottom).offset(1);
            make.height.equalTo(1);
        }];
    }
    return _locationTextField;
}


-(UITextField *) startTextField
{
    if(!_startTextField)
    {
        _startTextField = [[UITextField alloc]init];
        _startTextField.keyboardType = UIKeyboardTypeDefault;
        _startTextField.placeholder = @"开始日期";
        
        [_startTextField setStyle:^(UIView *target) {
            UITEXTFIELDSTYLE;
            temp.font = UILightFontMake(20);
            temp.textColor = UIColorMake(87, 83, 83);
            temp.textAlignment = NSTextAlignmentLeft;
        }];
        
        UIView *line= [UIView new];
        line.backgroundColor = UIColorMake(200, 199, 204);
        [_startTextField addSubview:line];
        [line makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(0);
            make.width.equalTo(_startTextField);
            make.top.equalTo(_startTextField.mas_bottom).offset(1);
            make.height.equalTo(1);
        }];
    }
    return _startTextField;
}


-(UITextField *) endTextField
{
    if(!_endTextField)
    {
        _endTextField = [[UITextField alloc]init];
        _endTextField.keyboardType = UIKeyboardTypeDefault;
        _endTextField.placeholder = @"截止日期";
        
        [_endTextField setStyle:^(UIView *target) {
            UITEXTFIELDSTYLE;
            temp.font = UILightFontMake(20);
            temp.textColor = UIColorMake(87, 83, 83);
            temp.textAlignment = NSTextAlignmentLeft;
        }];
        
        UIView *line= [UIView new];
        line.backgroundColor = UIColorMake(200, 199, 204);
        [_endTextField addSubview:line];
        [line makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(0);
            make.width.equalTo(_endTextField);
            make.top.equalTo(_endTextField.mas_bottom).offset(1);
            make.height.equalTo(1);
        }];
    }
    return _endTextField;
}


-(UITextField *) contentTextField
{
    if(!_contentTextField)
    {
        _contentTextField = [[UITextField alloc]init];
        _contentTextField.keyboardType = UIKeyboardTypeDefault;
        _contentTextField.placeholder = @"工作内容";
        
        [_contentTextField setStyle:^(UIView *target) {
            UITEXTFIELDSTYLE;
            temp.font = UILightFontMake(20);
            temp.textColor = UIColorMake(87, 83, 83);
            temp.textAlignment = NSTextAlignmentLeft;
        }];
        
        UIView *line= [UIView new];
        line.backgroundColor = UIColorMake(200, 199, 204);
        [_contentTextField addSubview:line];
        [line makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(0);
            make.width.equalTo(_contentTextField);
            make.top.equalTo(_contentTextField.mas_bottom).offset(1);
            make.height.equalTo(1);
        }];
    }
    return _contentTextField;
}
@end
